var QueueFactory = new QueuedHandler();
$(document).ready(function() {
    showProductImage();
    showAuctionAttributeTag();
    window.price = new Array();

});
function showProductImage() {
    $("#proImage img").not(":first").hide();
    $("#proThumbnail a").click(function() {
        if ($("#" + this.rel).is(":hidden")) {
            $("#proImage img").slideUp();
            $("#" + this.rel).slideDown()
        }
    }).focus(function() {
        $(this).blur()
    })
}
function showAuctionAttributeTag() {
    $(".countdownCap, .newGuy, .returnPoint, .bidMirror, .limitBid, .bidDegree, .bidReturnCap, .bidReturnAll, .freeBid, .combinationBid,.countdownRandom").mouseover(function() {
        $(this).attr("id", "currentTag");
        var self = $(this).attr("id");
        jt(self);
        var tagContent = $("#currentTag").attr("jtContent");
        $("#jtContent").html(tagContent)
    }).mouseout(function() {
        $("#jt").remove();
        $(this).attr("id", " ")
    })
};
function inibid(v) {
    if (v != '') {
        window._Fbid = 0;
        window._Alive = 0;
        window._R = 0;
        window._T = new Array();
        window._V = '0';
        window._C = 0;
        window._BID = new Array();
        window.BidTimer = null;
        window.ShowTimer = null;
        getVal();
        $(".bidbutton").mouseover(function() {
            var islogin = getCookie('islogin');
            var isfinish = $(this).hasClass("bidImgButton_ended");
            if (!islogin && !isfinish) {
                $(this).attr("class", "bidbutton bidImgButton bidImgButton_login")
            }
        });
        $(".bidbutton").mouseout(function() {
            var islogin = getCookie('islogin');
            var isfinish = $(this).hasClass("bidImgButton_ended");
            if (!islogin && !isfinish) {
                $(this).attr("class", "bidbutton bidImgButton bidImgButton_live")
            }
        });
        $(".bidbutton").click(function() {
            var bd = $(this).attr("id");
            var d = $(this).attr("name");
            var t = $(this).attr("title");
            var islogin = getCookie('islogin');
            var isfinish = $(this).hasClass("bidImgButton_ended");
            if (!isfinish) {
                if (!islogin) {
                    loadloginbox()
                } else {
                    if (bid(bd, d, t)) {
                        $(this).attr("class", "bidbutton bidImgButton bidImgButton_live")
                    }
                }
            }
        });
        $(".buynow").mouseover(function() {
            var islogin = getCookie('islogin');
            if (!islogin) {
                $(this).text('请先登录')
            }
        });
        $(".buynow").mouseout(function() {
            var islogin = getCookie('islogin');
            if (!islogin) {
                $(this).text('保价购买')
            }
        });
        $(".buynow").click(function() {
            var islogin = getCookie('islogin');
            var d = $(this).attr("name");
            if (!islogin) {
                loadloginbox()
            } else {
                if (buynow(d)) {
                    $(this).text('保价购买')
                }
            }
        });
        return true
    }
}
/*function getNews() {
    simajax(APP + "/Index/ajaxGetNews", "homenews");
    if (window.NewTimer != null) {
        window.clearTimeout(window.NewTimer)
    }
    window.NewTimer = window.setTimeout("getNews()", 900000)
}*/
/*function getAuction() {
    var _url = APP + "/Index/ajaxGetAuction";
    $.ajax({
        type: "POST",
        url: _url,
        success: function(str) {
            $("#liveAuctionList").html(str)
        }
    })
}*/
function getVal() {
    countRef();
}
function countRef() {
    window._C = window._C + 1;
    if (window._C >= 8) {
        window._R = 1;
        window._C = 0
    }
}


function dostatus(id, v) {
    var bidNo = window.inibidjs;
    var ids = bidNo.split(",");
    if (v == '0') {
        doTips(id);
        dostopstyle(id);
        clearbid(id);
    }
}
function HideDelay(dtime) {
    $("#proTop").hide();
    setCookie('delaybid', dtime)
}
function setGameDelay(intDelay, dtime) {
    var content = '<!-- 网络异 保护机制启动提示 -->' + '<h3 id="endedPrice">' + '<span class="price">提示：保护机制已启动</span>' + '</h3>' + '<div id="orderExpiryDate">' + '<p>' + WEBNAME + '已检测到网络异常，即将结束竞拍的倒计时+' + intDelay + '分钟。</p>' + '<p>本保护机制只有在网络异常下才会自动启动。<a href="http://www.paiban.com/News/detail/id/105" title="详细">详细</a></p>' + '</div>' + '<div id="userButton" class="fr">' + '<span id="closeProTop" class="button">' + '<span class="first-child">' + '<button type="button" class="strong f12" onclick="HideDelay(' + dtime + ')">关闭提示</button>' + '</span>' + '</span>' + '</div>' + '<!-- 网络异 保护机制启动提示 end -->';
    return content
}
function HideGame() {
    $("#freeToGet").hide()
}
function ShowGame(fid, gid, remain) {
    var content = setFunnyGame(fid, gid);
    $("#theResult").html(content);
    $("#freeToGet").show();
    window.setTimeout("HideGame()", remain)
}
function playFunnyGame(fid, gid) {
    $.ajax({
        type: "POST",
        data: {
            id: fid,
            game: gid
        },
        url: APP + "/Funnygame/playgame",
        success: function(data) {
            if ((data == "0") || (data == 0)) {
                HideGame();
                return
            }
            var v = eval(data);
            var sta = v[0];
            var msg = v[1];
            setCookie('funnygame', fid);
            $("#btnGetResult").attr("style", "display:none");
            $("#theResult").html(msg)
        }
    })
}
function setFunnyGame(fid, gid) {
    var isLogin = getCookie("islogin");
    if (isLogin == 1) {
        btnstr = '<button id="btnGetResult" type="button" class="f12" onclick="javascript:playFunnyGame(' + fid + ',' + gid + ');">我 抢</button>'
    } else {
        btnstr = '<button id="btnGetResult" type="button" class="f12" onclick="javascript:loadloginbox();">登 录</button>'
    }
    var content = '<span class="button" style="margin-bottom:15px;">' + '<span class="first-child">' + btnstr + '</span>' + '</span>';
    return content
}
/*function doCheckDelay() {
    $.ajax({
        type: "POST",
        timeout: _ajaxtimeout,
        data: {},
        url: APP + "/Auction/checkevn",
        success: function(tips) {
            var v = eval(tips);
            var info = v[0];
            var ext = v[1];
            var btime = v[3];
            if (ext == 6) {
                var delaybid = getCookie('delaybid');
                if (delaybid == btime) {
                    return
                }
                var intDelay = info;
                var content = setGameDelay(intDelay, btime);
                $("#alertOrderContent").html(content);
                $("#proTop").show();
                window.setTimeout("HideDelay(" + btime + ")", 120000)
            } else if (ext == 7) {
                var playgame = getCookie("funnygame");
                if (playgame == info) {
                    return
                }
                if ((v[4] != 0) && (v[4] != window.game_tid)) {
                    return
                }
                var delay = v[3] * 1000;
                var remain = v[2] * 1000;
                window.setTimeout("ShowGame(" + v[0] + "," + v[4] + "," + remain + ")", delay)
            }
        }
    });
    window.setTimeout("doCheckDelay()", 10000)
}*/
function HideTips() {
    $("#proTop").hide()
}

//结束后提示
function doTips(id) {
    $.ajax({
        type: "POST",
        timeout: _ajaxtimeout,
        url: APP + "/Auction/gamesTips",
        data: {
            "id": id
        },
        success: function(tips) {
            var v = eval(tips);
            var info = v[0];
            var ext = v[1];
            var t = v[2];
            var g = v[3];
            if (t == 0) {
                $("#proTop").hide()
            } else {
                $("#proTop").show();
                window.setTimeout("HideTips()", 30000);
                if (g == 1) {
                    var lastopplayer = info['lastopplayer'];
                    var lastopid = info['lastopid'];
                    var pname = info['productname'];
                    var content = setFunGameTips(lastopplayer, lastopid, pname);
                    $("#alertOrderContent").html(content)
                } else {
                    switch (ext) {
                    case 0:
                        var price = info['price'];
                        var time = info['endtime'];
                        var pname = info['productname'];
                        var grid = info['weight'];
                        var content = setGameTips0(price, pname, grid, time);
                        $("#alertOrderContent").html(content);
                        break;
                    case 1:
                        var lastopplayer = info['lastopplayer'];
                        var pname = info['productname'];
                        var price = info['price'];
                        var saleprice = info['saleprice'];
                        var time = info['endtime'];
                        var grid = info['weight'];
                        var content = setGameTips1(lastopplayer, price, pname, grid, saleprice, time);
                        $("#alertOrderContent").html(content);
                        break;
                    case 2:
                        var lastopplayer = info['lastopplayer'];
                        var backcounts = info['backcounts'];
                        var acount = info['acount'];
                        var bcount = info['bcount'];
                        var price = info['price'];
                        var saleprice = info['saleprice'];
                        var time = info['endtime'];
                        var pname = info['productname'];
                        var grid = info['weight'];
                        var content = setGameTips2(lastopplayer, price, saleprice, pname, grid, acount, bcount, backcounts, time);
                        $("#alertOrderContent").html(content);
                        break;
                    case 3:
                        var lastopplayer = info['lastopplayer'];
                        var price = info['price'];
                        var pname = info['productname'];
                        var content = setGameTips3(lastopplayer, price, pname);
                        $("#alertOrderContent").html(content);
                        break;
                    case 4:
                        var lastopplayer = info['lastopplayer'];
                        var price = info['price'];
                        var pname = info['productname'];
                        var acount = info['acount'];
                        var bcount = info['bcount'];
                        var backcounts = info['backcounts'];
                        var content = setGameTips4(lastopplayer, pname, price, acount, bcount, backcounts);
                        $("#alertOrderContent").html(content);
                        break;
                    case 5:
                        var lastopplayer = info['lastopplayer'];
                        var price = info['price'];
                        var pname = info['productname'];
                        var content = setGameTips5(lastopplayer, price, pname);
                        $("#alertOrderContent").html(content);
                        break;
                    default:
                        break
                    }
                }
            }
        }
    })
}
function setFunGameTips(winner, winnerid, pname) {
    var content = '<h3 id="endedPrice">恭喜' + winner + '刚刚在趣味区' + '拍得[ ' + pname + ' ]' + '</h3>' + '<div id="orderExpiryDate">' + '<p class="notice">公平竞拍的环境需要您的支持，请勿触犯' + WEBNAME + '一人多号规则，再次提醒用户阅读' + '<a href="' + APP + '/Article/index/id/16" title="查看违规处理">《违规处理》</a>' + '、' + '<a href="' + APP + '/Article/index/id/16" title="查看违规处理">《使用条款》</a>' + '</p>' + '</div>' + '<div id="userButton" class="fr">' + '<span id="closeProTop" class="button">' + '<span class="first-child">' + '<button type="button" class="strong f12" onclick="HideTips()">关闭提示</button>' + '</span>' + '</span>' + '</div>';
    return content
}
function setGameTips0(price, pname, grid, time) {
    var content = '<h3 id="endedPrice">恭喜，您以' + '<span class="price">¥' + price + '</span>拍得[ ' + pname + ' ]！' + '</h3>' + '<div id="orderExpiryDate">' + '<p>订单有效期至<strong>' + time + '</strong>，请及时支付订单，逾期视为放弃购买。</p>' + '<p class="notice">您已拍得商品，切勿触犯' + WEBNAME + '一人多号规则，再次提醒用户阅读' + '<a href="' + APP + '/Article/index/id/16" title="查看违规处理">《违规处理》</a>' + '、' + '<a href="' + APP + '/Article/index/id/16" title="查看违规处理">《使用条款》</a>' + '</p>' + '</div>' + '<div id="userButton" class="fr">' + '<span class="button button-hilite">' + '<span class="first-child">' + '<button type="button" class="strong f12" onclick="goToURL()">前往操作</button>' + '</span>' + '</span>' + '<span id="closeProTop" class="button">' + '<span class="first-child">' + '<button type="button" class="strong f12" onclick="HideTips()">关闭提示</button>' + '</span>' + '</span>' + '</div>';
    return content
}
function setGameTips1(lastopplayer, price, pname, grid, dcount, time) {
    var content = '<h3 id="endedPrice">[ ' + pname + ' ]竞拍已结束！您可补差价' + '<span class="price">¥' + dcount + '</span>进行保价购买，不浪费一分钱' + '</h3>' + '<div id="orderExpiryDate">' + '<p>订单有效期至<strong>' + time + '</strong>，' + '请及时支付订单，逾期视为放弃购买。</p>' + '<p class="notice">您已拍得商品，再次提醒用户阅读' + '<a href="' + APP + '/Article/index/id/16" title="查看违规处理">《违规处理》</a>' + '、' + '<a href="' + APP + '/Article/index/id/16" title="查看违规处理">《使用条款》</a>' + '</p>' + '</div>' + '<div id="userButton" class="fr">' + '<span class="button button-hilite">' + '<span class="first-child">' + '<button type="button" class="strong f12" onclick="goToURL()">前往操作</button>' + '</span>' + '</span>' + '<span id="closeProTop" class="button">' + '<span class="first-child">' + '<button type="button" class="strong f12" onclick="HideTips()">关闭提示</button>' + '</span>' + '</span>' + '</div>';
    return content
}
function setGameTips2(lastopplayer, price, saleprice, pname, grid, acount, bcount, backcounts, time) {
    var content = '<h3 id="endedPrice">[ ' + pname + ' ]竞拍已结束！' + '您获得第二名返点资格' + '</h3>' + '<div id="orderExpiryDate">' + '<p>订单有效期至<strong>' + time + '</strong>，' + '您可选择补差价<span class="price">¥' + saleprice + '</span>“保价购买”或选择返点<strong>' + backcounts + '</strong>'+POINTBNAME+'。' + '<p>竞拍已结束，请参与其他竞拍，切勿触犯' + WEBNAME + '一人多号规则，再次提醒用户阅读' + '<a href="' + APP + '/Article/index/id/16" title="查看违规处理">《违规处理》</a>' + '、' + '<a href="' + APP + '/Article/index/id/16" title="查看违规处理">《使用条款》</a>' + '</p>' + '</div>' + '<div id="userButton" class="fr">' + '<span class="button button-hilite">' + '<span class="first-child">' + '<button type="button" class="strong f12" onclick="goToURL()">前往操作</button>' + '</span>' + '</span>' + '<span id="closeProTop" class="button">' + '<span class="first-child">' + '<button type="button" class="strong f12" onclick="HideTips()">关闭提示</button>' + '</span>' + '</span>' + '</div>';
    return content
}
function setGameTips3(lastopplayer, price, pname) {
    var content = '<h3 id="endedPrice">' + lastopplayer + '刚以' + '<span class="price">¥' + price + '</span>获得了商品[ ' + pname + ' ]' + '</h3>' + '<div id="orderExpiryDate">' + '<p>本次竞拍已结束，请参与其他竞拍!' + '</p>' + '<p></p>' + '</div>' + '<div id="userButton" class="fr">' + '<span id="closeProTop" class="button">' + '<span class="first-child">' + '<button type="button" class="strong f12" onclick="HideTips()">关闭提示</button>' + '</span>' + '</span>' + '</div>';
    return content
}
function setGameTips4(lastopplayer, pname, price, acount, bcount, backcounts) {
    var content = '<h3 id="endedPrice">[ ' + pname + ' ]竞拍已结束，' + lastopplayer + '以<span class="price">¥' + price + '</span>获得了该商品！' + '</h3>' + '<div id="orderExpiryDate">' + '<p>本次竞拍为全额返'+BEATNAME+'，返点工作将在第三个工作日进行。您一共消耗闪点'+BEATNAME+'：<strong>' + acount + '</strong>，'+POINTBNAME+'：<strong>' + bcount + '</strong>，返点数额：<strong>' + backcounts + '</strong>闪点</p>' + '<p>竞拍已结束，请参与其他竞拍，切勿触犯' + WEBNAME + '一人多号规则，再次提醒用户阅读' + '<a href="' + APP + '/Article/index/id/16" title="查看违规处理">《违规处理》</a>' + '、' + '<a href="' + APP + '/Article/index/id/16" title="查看违规处理">《使用条款》</a>' + '</p>' + '</div>' + '<div id="userButton" class="fr">' + '<span class="button button-hilite">' + '<span class="first-child">' + '<button type="button" class="strong f12" onclick="goToURL()">前往操作</button>' + '</span>' + '</span>' + '<span id="closeProTop" class="button">' + '<span class="first-child">' + '<button type="button" class="strong f12" onclick="HideTips()">关闭提示</button>' + '</span>' + '</span>' + '</div>';
    return content
}
function setGameTips5(lastopplayer, price, pname) {
    var content = '<h3 id="endedPrice">恭喜，' + lastopplayer + '刚以' + '<span class="price">¥' + price + '</span>获得了商品[ ' + pname + ' ]</h3>' + '<div id="orderExpiryDate">' + '<p>本次竞拍为免费竞拍，无需消耗任何点数即可出价，更多活动请关注公告。</p>' + '<p>竞拍已结束，请参与其他竞拍，切勿触犯' + WEBNAME + '一人多号规则，再次提醒用户阅读' + '<a href="' + APP + '/Article/index/id/16" title="查看违规处理">《违规处理》</a>' + '、' + '<a href="' + APP + '/Article/index/id/16" title="查看违规处理">《使用条款》</a>' + '</p>' + '</div>' + '<div id="userButton" class="fr">' + '<span class="button button-hilite">' + '<span class="first-child">' + '<button type="button" class="strong f12" onclick="goToURL()">前往操作</button>' + '</span>' + '</span>' + '<span id="closeProTop" class="button">' + '<span class="first-child">' + '<button type="button" class="strong f12" onclick="HideTips()">关闭提示</button>' + '</span>' + '</span>' + '</div>';
    return content
}
function goToURL() {
    location.href = APP + '/Member/'
}
function closeTips() {
    $('#proTop').attr("style", "display:none")
}
function dobider(key,name,uid,head) {
	var bidder_id = "#bidder_" + key;
    var bidder_icon = "#bidder_icon_" + key;
    if (name != '') {
        $(bidder_id).text(name);
        $(bidder_id).attr("href", APP + "/User/center/id/" + uid);
        $(bidder_id).attr("target", "_blank");
        $(bidder_id).attr("title", "去看看" + name);
        $(bidder_icon).html('<img src="'+ROOT+'/Public/images/head/s/' + head + '" />');
        $(bidder_icon).attr("href", APP + "/User/center/id/" + uid);
        $(bidder_icon).attr("target", "_blank");
        $(bidder_icon).attr("title", "去看看" + name);
    } else {
        $(bidder_id).text('----');
        $(bidder_id).attr("title", "暂无用户竞拍");
        $(bidder_icon).html('<img src="'+ROOT+'/Public/images/head/s/userDefaultIcon.gif" />');
    }
}
function doprice(key, v) {
	var id = "#price_" + key;
    v = Ftmath(v);
    $(id).text("¥" + v);
    if (window.price['price_'+key]!= v) {
        $(id).highlightFade({
            color: 'red',
            speed: 800
        })
    }
    price['price_'+key] = v;
}
function dotime(key, v) {
    var id = $('#time_'+key);
    id.countdown('destroy');
	id.countdown({
		until: v, 
		compact: true,
		format: 'HMS',
		expiryText:"即将成交",
		onTick:function(periods){
			timeslot(periods,key);
		}
	});
}

//对于时间段颜色的操作
function timeslot(periods,key){
	var key = 'time_'+key;
	var id = $('#'+ key);
	var time = periods[4]*3600 + periods[5]*60 + periods[6];

		if(time < 30){
			if(time < 20){
				if(time < 10){
					if(window._T[key] != 'red'){
						id.css("color","red");
						window._T == 'red';
					}
				}else{
					if(window._T[key] != 'green'){
						id.css("color","green");
						window._T == 'green';
					}
				}
			}else{
				
				if(window._T[key] != 'yellow'){
					id.css("color","yellow");
					window._T[key] == 'yellow';
				}
			}
		}else{
			if(window._T[key] != 'black'){
				id.css("color","black");
				window._T[key] == 'black';
			}
		}
}

function getLocTime(id, key, t) {
    if (window._Alive >= 2) {
        return ('<font color="#A6A6A6" >网络连接慢</font>')
    } else {
        if (t <= -3) {
            return ("--:--:--")
        } else {
            if (t <= 0) {
                window._R = 1;
                if (window._BID[key][3] == 0) {
                    return ('<font color="red">即将成交</font>')
                } else {
                    return ("--:--:--")
                }
            } else {
                if (t > 60 * 60 * 24) {
                    var h = Div(t, (60 * 60));
                    var i = Div(Mod(Mod(t, (60 * 60 * 24)), (60 * 60)), 60);
                    var s = Mod(Mod(Mod(t, (60 * 60 * 24)), (60 * 60)), 60);
                    return (Ft(h) + ':' + Ft(i) + ':' + Ft(s))
                } else if (t > 60 * 60) {
                    var h = Div(t, (60 * 60));
                    var i = Div(Mod(t, (60 * 60)), 60);
                    var s = Mod(Mod(t, (60 * 60)), 60);
                    return (Ft(h) + ':' + Ft(i) + ':' + Ft(s))
                } else if (t > 60) {
                    var i = Div(t, 60);
                    var s = Mod(t, 60);
                    return ('00:' + Ft(i) + ':' + Ft(s))
                } else if (t > 30) {
                    return ('<font color="green">00:00:' + Ft(t) + '</font>')
                } else if (t > 0) {
                    return ('<font color="red">00:00:' + Ft(t) + '</font>')
                }
            }
        }
    }
}

//结束 都设置为空
function dostopstyle(id) {
    $("#time_" + id).text('--:--:--').attr('style', 'color:#a6a6a6');
    $("#bid_btn_" + id).addClass('button-disabled');
    $("#" + id).attr("class", "bidbutton bidImgButton bidImgButton_ended");
    if (id == window.topbid) {
        $("#top_time_" + id).text('--:--:--').attr('style', 'color:#a6a6a6');
        $("#top_bid_btn_" + id).addClass('button-disabled');
        $("#top_" + id).attr("class", "bidbutton bidImgButton bidImgButton_ended")
    }
}
function dosave(id, saveprice, price) {
    var v = saveprice - price;
    v = "¥" + Ftmath(v);
    $(id).text(v)
}

//结束去掉里面的这个竞拍
function clearbid(n) {
    var ids = window.inibidjs.split(",");
    var tempvar = new Array();
    var k = 0;
    for (var i = 0; i < ids.length; i++) {
        if (n != ids[i]) {
            tempvar[k++] = ids[i]
        }
    }
    window.inibidjs = tempvar.join(',')
}

function bid(id, key) {
    $.ajax({
        type: "POST",
        //timeout: _ajaxtimeout,
        url: ROOT + "/bid.php",
        data: {
            "id": key
        },
        success: function(vv) {
            v = eval(vv);
            msg = v[0];
            ext = v[1];
            if (msg == 1) {
                showBidTip(id, '<span>出价成功，消耗<strong style="color:#ff0000">' + ext + '点</strong></span>');
                window._R = 1;
                window.setTimeout("up_self()", 500)
            } else if (msg == 0) {
				showBidTip(id, '此竞拍已结束')
			} else if (msg == 2) {
                showBidTip(id, '请先登录')
            } else if (msg == 3) {
                showBidTip(id, '您的余额不足，请充值!<a href="javascript:paycountnow();" title="充值，获取'+BEATNAME+'">【马上充值】</a>')
            } else if (msg == 4) {
                var msg = '<div class="tc"><span class="button"><span class="first-child"><button onclick="removeDialogbox(\'#userAway\');" type="button">您已出价，无需重复!</button></span></span></div>';
                addDialogbox("#userAway", WEBNAME + '提示', 10010, 300);
                $("#userAway .dialogboxContent").html(msg)
            } else if (msg == 5) {} else if (msg == 6) {
                showBidTip(id, '现已经到达封盘时段（00:00 - 09:00），请于开盘时再竞拍')
            } else if (msg == 7) {
                showBidTip(id, '此竞拍不存在')
            } else if (msg == 8) {
                showBidTip(id, '竞拍未开始');
            } else if (msg == 9) {
                showBidTip(id, '异常错误');
            } else if (msg == 10) {
                showBidTip(id, '您已获得过商品，此为新人竞拍商品')
            } else if (msg == 11) {
                showBidTip(id, '您出价太快，请放松')
            } else if (msg == 12) {
                showBidTip(id, '此为新人竞拍商品，请先进行账户安全认证')
            } else if (msg == 13) {
                showBidTip(id, '检测点击频率太快，暂停出价30秒')
            } else if (msg == 14) {
                showBidTip(id, '您已设置分身进行竞拍，请取消或者等待分身出价结束后再操作！')
            } else if (msg == 15) {
                showBidTip(id, '本期是"N次拍"游戏,您的出价已经达到"N次拍"玩法的次数的上限！')
            } else if (msg == 16) {
                showBidTip(id, '本次竞拍只限' + ext + '期出价的闪友！')
            } else if (msg == 17) {
                showBidTip(id, '竞拍封顶规则限制，您不能参与此次竞拍！')
            } else if (msg == 18) {
                showBidTip(id, '您已获得过此商品，不能参与此次竞拍！')
            } else if (msg == 19) {
                showBidTip(id, '相同网络地址已有会员出价，您不能参与此次竞拍！')
            } else if (msg == 20) {
                showBidTip(id, '您的出价已经达到本期竞拍出价次数上限！')
            } else {}
        }
    })
}
function showBidTip(id, text) {
    jt($("#" + id).parent().parent().attr("id"));
    $("#jtContent").html(text);
    function showJT() {
        $("#jt").fadeOut("fast", 
        function() {
            $(this).remove()
        })
    }
    var tt = window.setTimeout(showJT, 1500);
    $("#jt").hover(function() {
        window.clearTimeout(tt)
    },
    function() {
        tt = window.setTimeout(showJT, 1000)
    });
    $("#jt").blur(function() {
        showJT()
    })
}
function buynow(id) {
    var buyId = "buy_" + id;
    QueueFactory.request({
        type: "POST",
        url: APP + "/Auction/buynow/id/" + id,
        success: function(msg) {
            if (msg == 0) {
                showBidTip(buyId, '保价购买成功，本期竞拍结束后将生成保价订单。<br /><br />在这个过程中仍然可以参与竞拍，以争取获更低的价格。')
            } else if (msg == 1) {
                showBidTip(buyId, '保价失败，请重试')
            } else if (msg == 2) {
                showBidTip(buyId, '请先登录，后再进行保价购买')
            } else if (msg == 3) {
                showBidTip(buyId, '您已保价，本期竞拍结束后将生成保价订单。请不要重复点击！')
            }
        }
    })
}
function showbidtips(id, tex) {
    var target = 'bidtips_' + id;
    $('#' + target).html(tex);
    setTimeout("closetips2('" + target + "')", 2000)
}
function setMirror(tid) {
    var startprice = $("#mr_startprice").val();
    var settingcount = $("#mr_settingcount").val();
    $("#mr_bidcount").val("0");
    $.post(APP + '/Bid/setdaemon', {
        "tid": tid,
        "startprice": startprice,
        "settingcount": settingcount
    },
    function(data) {
        if (data == '9') {
            alert('分身启动成功!');
            $("#mr_stopbid").removeClass("showButton");
            $("#mr_startbid").addClass("showButton")
        } else {
            alert('启动分身失败!')
        }
    })
}
function ctrlauction(n) {
    if (n == 0) {
        window.chat_status = 0;
        window.self_status = 0;
        window.auto_status = 0;
        if (window.history_status == 0) {
            window.history_status = 1;
            up_history()
        }
    } else if (n == 1) {
        window.chat_status = 0;
        window.auto_status = 0;
        window.history_status = 0;
        if (window.self_status == 0) {
            window.self_status = 1;
            up_self()
        }
    } else if (n == 2) {
        window.self_status = 0;
        window.auto_status = 0;
        window.history_status = 0;
        if (window.chat_status == 0) {
            window.chat_status = 1;
            up_chat()
        }
    } else if (n == 3) {
        window.chat_status = 0;
        window.self_status = 0;
        window.history_status = 0;
        up_auto()
    }
}
function up_history() {
    var tid = window.game_tid;
    var bidNo = window.inibidjs;
    if (window.history_status == 1 && bidNo != '') {
        QueueFactory.request({
            type: "POST",
            dataType: "json",
            //timeout: _ajaxtimeout,
            url: ROOT + "/bidhistory.php?id=" + tid,
            success: function(data) {
                update_all_bidhistorylist(data.all, 1)
            }
        })
    }
}
function up_auto() {
    if (window.auto_status == 1) {
        SetAutobid();
        window.setTimeout("up_auto()", 3000)
    }
}
function up_self() {
    var tid = window.game_tid;
    var islogin = getCookie('islogin');
    var js_saveprice = $('#js_saveprice').val();
    if (window.self_status == 1 && islogin) {
        $.getJSON(APP + "/Auction/ajaxmycount/id/" + tid, 
        function(data) {
            $('#self_point_a').html(data.self_point_a + "点");
            $('#self_point_b').html(data.self_point_b + "点");
            $('#self_price_point_a').html("¥" + data.self_price_point_a);
            $('#self_price_point_a2').html("¥" + data.self_price_point_a);
            $('#self_bidcount').html(data.self_bidcount + "次");
            if (data.self_price_point_a / js_saveprice > 0.8) {
                $('#bidNotes').html("<font color='red'>您很快就要达到保价了，请理性出价</font>")
            }
            if (js_saveprice - data.self_price_point_a > 0) {
                $('#self_price_pay').html("¥" + (js_saveprice - data.self_price_point_a))
            } else {
                $('#self_price_pay').html("¥0")
            }
        })
    } else {
        $('#self_point_a').html("0点");
        $('#self_point_b').html("0点");
        $('#self_clicks').html("0次");
        $('#self_bidcount').html("0次");
        $('#self_price_point_a').html("¥0");
        $('#self_price_point_a2').html("¥0");
        $('#self_next_spend').html("0点/每次点击");
        $('#self_price_point_a').html("¥0");
        $('#self_price_pay').html("¥" + js_saveprice)
    }
}
function update_all_bidhistorylist(d, n) {
    var tid = window.game_tid;
    var data_all = d;
    var htmlvar;
    var html_header = '<table class="chart"><thead><th width="20%">ID</th><th width="30%">IP</th><th width="20%">类型</th><th width="30%">出价</th></thead>';
    var html_footer = '</table><div class="pages cb" style="font-size:12px;"> <a jtcontent="由于网络原因，竞拍记录有可能不同步，请点击【马上整理出价记录!】" jtwidth="150" jttitle="提示" id="bidalllisttips" href="javascript:void(0);" onclick="ctrlauction(0);">[马上整理出价记录!]</a></div>';
    var html_body = '';
    var item_num = 0;
    var item_type = '';
    $.each(data_all, 
    function(i, item) {
        if (i == 0) {
            window.r_id = item.id
        }
        item_num++;
        /*if (item.bidtype == 0) {
            item_type = '手动'
        } else {
            item_type = '分身'
        }*/
		
        html_body += '<tr title="闪友来自:' + item.locate + ',出价时间:' + item.bidtime + '"><td><a style="display:block; height:16px; overflow:hidden;" href="' + APP + '/User/center/id/' + item.mid + '" target="_blank" title="去看看' + item.nickname + '，昵称过长自动隐藏">' + item.nickname + '</a></td><td class="f10 notice">' + item.ip + '</td><td class="notice">' + '手动' + '</td><td class="f10 notice">¥' + item.price + '</td></tr>'
    });
    if (n == 1) {
        $('#bidHistoryList').html(html_header + html_body + html_footer);
        showTip("bidalllisttips")
    } else {
        if ($("#bidHistoryList table tr").size() > 9) {
            for (i = 0; i < item_num; i++) {
                $("#bidHistoryList table tr:last").remove()
            }
        }
        $("#bidHistoryList table").prepend(html_body)
    }
}
var pClass = 'message_a';
function sendchat() {
    var islogin = getCookie('islogin');
    if (islogin == 1) {
        if ($("#msg").val() != '') {
            $.post(APP + "/Chat/add", {
                tid: game_tid,
                msg: $("#msg").val(),
                mid: $("#usermid").val(),
                username: $("#usernickname").val(),
                ip: $("#ip").val(),
                time: window.timestamp
            },
            function(xml) {
                $("#msg").val("");
                addMessages(xml)
            })
        }
    }
    return false
}
function up_chat() {
    var tid = window.game_tid;
    var islogin = getCookie('islogin');
    if (islogin != 1) {
        $("#msg").attr('disabled', 'disabled').attr('value', '请登录后刷新页面!');
        $("#sendmsg").attr('disabled', 'disabled')
    } else {
        $("#msg").removeAttr('disabled');
        $("#sendmsg").removeAttr('disabled')
    }
    if (window.chat_status == 1) {
        var uptime = window.timestamp;
        $.post(APP + "/Chat/get/", {
            time: uptime,
            tid: tid
        },
        function(xml) {
            $("#chatloading").remove();
            addMessages(xml)
        });
        window.setTimeout("up_chat()", 4000)
    }
}
function addMessages(xml) {
    var cClass;
    if ($("status", xml).text() == "2") return;
    window.timestamp = $("time", xml).text();
    $("message", xml).each(function(n, i) {
        var username = $("username", this).text();
        var mid = $("mid", this).text();
        var time = $("time", this).text();
        var ip = $("ip", this).text();
        var ptime = $("ptime", this).text();
        var content = $("text", this).text();
        if (pClass == 'message_a') {
            cClass = "message_b";
            pClass = "message_b"
        } else {
            cClass = "message_a";
            pClass = "message_a"
        }
        if (mid == "MTg2YTg=") {
            cClass = "paibanAdmin"
        }
        var htmlcode = '<tr><td class="' + cClass + '">' + '<p><span class="userName">' + username + '</span>' + '<span class="f10">' + ptime + '</span></p>' + '<p class="userMessage">' + toBreakWord(content, 30) + '</p>' + '</td></tr>';
        $("#chatList").append(htmlcode);
        $("#chatwindow").get(0).scrollTop = $("#chatList").get(0).scrollHeight
    });
    pClass = cClass
}
$(document).ready(function() {
    $.formValidator.initConfig({
        formid: "commentsform",
        validatorgroup: "commentsform",
        autotip: true
    });
    $("#commentContent").formValidator({
        validatorgroup: "commentsform",
        empty: false,
        tipid: 'commentContentTips',
        onshow: "请输入评论内容",
        onfocus: "评论字数请介于10到200之间!",
        oncorrect: "正确"
    }).inputValidator({
        min: 10,
        max: 200,
        onerror: "评论字数请介于10到200之间!"
    });
    $("#comments_add").click(function() {
        var islogin = getCookie('islogin');
        var pass = $.formValidator.pageIsValid('commentsform');
        if (islogin) {
            if (pass) {
                var queryString = $('#commentsform').formSerialize();
                $.post(APP + "/Auction/productdiscussadd", queryString, 
                function(msg) {
                    if (msg == '0') {
                        showtips('评论信息成功!', 'ajaxTips', 1);
                        simajax(APP + '/Auction/ajax_getproductdiscuss/pid/' + game_pid, 'commentslist')
                    } else {
                        showtips(msg, 'ajaxTips', 2)
                    }
                });
                $('#commentContent').val('')
            }
        } else {
            showtips('请先登陆,再评论!', 'ajaxTips', 2)
        }
    });
    $("#comments_add").mouseover(function() {
        var islogin = getCookie('islogin');
        if (!islogin) {
            $(this).text('请先登陆,再评论!')
        }
    });
    $("#comments_add").mouseout(function() {
        var islogin = getCookie('islogin');
        if (!islogin) {
            $(this).text('写完了，发送')
        }
    });
    $("#mbcomments_add").click(function() {
        var islogin = getCookie('islogin');
        var pass = $.formValidator.pageIsValid('commentsform');
        var tid = $("#tid").val();
        if (islogin) {
            if (pass) {
                var queryString = $('#commentsform').formSerialize();
                $.post(APP + "/User/mbdiscussadd", queryString, 
                function(msg) {
                    if (msg == '0') {
                        showtips('评论信息成功!', 'ajaxTips', 1);
                        simajax(APP + '/User/mbdiscuss/tid/' + tid, 'commentslist')
                    } else {
                        showtips(msg, 'ajaxTips', 2)
                    }
                });
                $('#commentContent').val('')
            }
        } else {
            showtips('请先登陆,再评论!', 'ajaxTips', 2)
        }
    });
    $("#mbcomments_add").mouseover(function() {
        var islogin = getCookie('islogin');
        if (!islogin) {
            $(this).text('请先登陆,再评论!')
        }
    });
    $("#mbcomments_add").mouseout(function() {
        var islogin = getCookie('islogin');
        if (!islogin) {
            $(this).text('写完了，发送')
        }
    });
    $("#sendonemsg").click(function() {
        var islogin = getCookie('islogin');
        var mid = $(this).attr("name");
        if (islogin) {
            addDialogbox("#mbsendonemsg", "发送站内信息", 10001, 505);
            $.ajax({
                url: APP + "/User/mbsendmsg/mid/" + mid,
                cache: false,
                success: function(msg) {
                    $("#mbsendonemsg .dialogboxContent").prepend(msg)
                }
            })
        } else {
            $(this).text('请先登陆!')
        }
    });
    $("#sendonemsg").mouseover(function() {
        var islogin = getCookie('islogin');
        if (!islogin) {
            $(this).text('请先登陆!')
        }
    });
    $("#sendonemsg").mouseout(function() {
        var islogin = getCookie('islogin');
        if (!islogin) {
            $(this).text('给TA留下一句话')
        }
    })
});
function categories() {
    var $categories = $("#brandCategories li");
    var $categoriesLi = $("#brandCategories ul li");
    $categories.hide();
    $("#more").click(function() {
        if ($categories.is(":visible")) {
            $categories.hide();
            $(this).text("展开全部品牌")
        } else {
            $categories.show();
            $(this).text("隐藏显示品牌")
        }
        return false
    }).focus(function() {
        $(this).blur()
    })
}
function iniautobid() {
    window.auto_status = 1;
    $("#mr_startbid").mouseover(function() {
        var islogin = getCookie('islogin');
        if (!islogin) {
            $(this).attr("value", '登录')
        }
    });
    $("#mr_startbid").mouseout(function() {
        var islogin = getCookie('islogin');
        if (!islogin) {
            $(this).attr("value", '开始')
        }
    });
    $("#mr_startbid").click(function() {
        var islogin = getCookie('islogin');
        if (!islogin) {
            loadloginbox()
        } else {
            setdaemon()
        }
    });
    $("#mr_stopbid").mouseover(function() {
        var islogin = getCookie('islogin');
        if (!islogin) {
            $(this).attr("value", '登录')
        }
    });
    $("#mr_stopbid").mouseout(function() {
        var islogin = getCookie('islogin');
        if (!islogin) {
            $(this).attr("value", '取消')
        }
    });
    $("#mr_stopbid").click(function() {
        var islogin = getCookie('islogin');
        if (!islogin) {
            loadloginbox()
        } else {
            unsetdaemon()
        }
    })
}
function SetAutobid() {
    var tid = window.game_tid;
    var islogin = getCookie('islogin');
    if (!islogin) {
        $("#mr_startbid").show();
        $("#mr_stopbid").hide();
        autosetform(0);
        return
    } else {
        $.post(APP + "/Bid/daemon", {
            "tid": tid
        },
        function(dt) {
            if (dt == '0') {
                window.auto_status = 0;
                $("#mr_startbid").show();
                $("#mr_stopbid").hide();
                autosetform(1);
                if (window.auto_id > 0) {
                    window.auto_id = 0;
                    reSetAutobid()
                }
            } else {
                window.auto_status = 1;
                window.auto_id = dt.id;
                $("#mr_startprice").val(dt.startprice);
                $("#mr_settingcount").val(dt.settingcount);
                $("#mr_bidcount").text(dt.bidcount);
                if (window.auto_timer == 0) {
                    window.auto_timer = 1;
                    dostyle_mr_startbid()
                }
            }
        },
        'json')
    }
}
function reSetAutobid() {
    var tid = window.game_tid;
    var islogin = getCookie('islogin');
    if (!islogin) {
        $("#mr_startbid").show();
        $("#mr_stopbid").hide();
        autosetform(0);
        return
    } else {
        $.post(APP + "/Bid/daemon", {
            "tid": tid,
            "flag": 1
        },
        function(dt) {
            $("#mr_startprice").val(dt.startprice);
            $("#mr_settingcount").val(dt.settingcount);
            $("#mr_bidcount").text(dt.bidcount)
        },
        'json')
    }
}
function setdaemon() {
    var tid = window.game_tid;
    var startprice = $("#mr_startprice").val();
    var settingcount = $("#mr_settingcount").val();
    var nowprice = window._BID[tid][3];
    if (startprice < nowprice) {
        showBidTip('autobid_tip', '价格不能小于现价!');
        return
    }
    $.post(APP + "/Bid/setdaemon", {
        "tid": tid,
        "startprice": startprice,
        "settingcount": settingcount
    },
    function(msg) {
        if (msg == 0) {
            showBidTip('autobid_tip', '请登陆后再试!')
        } else if (msg == 1) {
            showBidTip('autobid_tip', '超出设置次数上限!')
        } else if (msg == 2) {
            showBidTip('autobid_tip', '参数错误!')
        } else if (msg == 4) {
            showBidTip('autobid_tip', '你已达到封顶!')
        } else if (msg == 7) {
            showBidTip('autobid_tip', '资金已冻结!')
        } else if (msg == 8) {
            showBidTip('autobid_tip', '会员已冻结!')
        } else if (msg == 9) {
            dostyle_mr_startbid();
            window.auto_status = 1;
            up_auto()
        } else {}
    })
}
function unsetdaemon() {
    var tid = window.game_tid;
    var id = window.auto_id;
    $.post(APP + "/Bid/disposedaemon", {
        "id": id
    },
    function(msg) {
        if (msg == 0) {
            showBidTip('mr_stopbid', '请登陆后再试!')
        } else if (msg == 1) {
            showBidTip('mr_stopbid', '检查出错!')
        } else if (msg == 2) {
            showBidTip('mr_stopbid', '更新出错!')
        } else if (msg == 3) {
            showBidTip('mr_stopbid', '未到取消时间!')
        } else if (msg == 9) {
            dostyle_mr_stopbid()
        } else {}
    })
}
function dostyle_mr_startbid() {
    $("#mr_startbid").hide();
    $("#mr_stopbid").show();
    window.startautobid = 1;
    autosetform(0)
}
function dostyle_mr_stopbid() {
    $("#mr_stopbid").hide();
    $("#mr_startbid").show();
    window.startautobid = 0;
    autosetform(1)
}
function UpdateTime(num, se, toid) {
    $("#" + toid).attr("value", "[" + (se - num) + "秒]")
}
function UpdateTimeOn(toid, v) {
    $("#" + toid).attr("value", v);
    $("#" + toid).removeAttr("disabled")
}
function autosetform(n) {
    if (n == 0) {
        $("#mr_startprice").attr("disabled", "disabled");
        $("#mr_settingcount").attr("disabled", "disabled")
    }
    if (n == 1) {
        $("#mr_startprice").removeAttr("disabled");
        $("#mr_settingcount").removeAttr("disabled")
    }
}
function gohistorylist() {
    var passurls;
    var brands = $("#brands").attr("value");
    var price = $("#price").attr("value");
    passurls = APP + "/Auction/historylist";
    if (brands != '0') {
        passurls = passurls + "/brands/" + brands
    }
    if (price != '0') {
        passurls = passurls + "/price/" + price
    }
    window.location.href = passurls
}
function gofuturelist() {
    var passurls;
    var brands = $("#brands").attr("value");
    var savingprice = $("#savingprice").attr("value");
    passurls = APP + "/Auction/futurelist";
    if (brands != '0') {
        passurls = passurls + "/brands/" + brands
    }
    if (savingprice != '0') {
        passurls = passurls + "/savingprice/" + savingprice
    }
    window.location.href = passurls
}
function exchange(id){
	var url=APP+"/Mall/buy/id/"+id;
	$.ajax({
		url: APP+"/Mall/buy/id/"+id,
		cache: false,
		success: function(msg){
			if(msg==1){
				showBidTip(id, '请登陆后再试!');
			} else if (msg == 2) {
				showBidTip(id, '操作错误!');
            }else{
                window.location.href = url;
			}
		}
	});
}
function buyurl(){
	var url=APP+"/Mall/index/";
	window.location.href = url;
}

function buycheck(){
	var queryString = $('#buyMallForm').formSerialize();
	var id=$("#id").val(); 
	//alert(id);
	
	$.post(APP+"/Mall/check", queryString,function(msg){
		if(msg=='0'){ 
			showBidTip(id,'兑换成功!');
			setTimeout("buyurl()",3000);			
		}else if(msg=='1'){ 
			showBidTip(id,'请登录!');
		}else if(msg=='2'){ 
			showBidTip(id,'操作错误!');
		}else if(msg=='3'){ 
			showBidTip(id,'数量不能为空!');
		}else if(msg=='4'){ 
			showBidTip(id,'收件人不能为空!');
		}else if(msg=='5'){ 
			showBidTip(id,'邮编不能为空!');
		}else if(msg=='6'){ 
			showBidTip(id,'收货地址不能为空!');
		}else if(msg=='7'){ 
			showBidTip(id,'收件人手机号不能为空!');
		}else if(msg=='8'){
			showBidTip(id, '积分不足!');
		}else if(msg=='9'){ 
			showBidTip(id,'库存不足!');
		}else{
			showBidTip(id, '兑换失败!');
		}
	});
	//$("#buyMallForm").submit();
}